import Vue from 'vue'
import Router from 'vue-router'

// 固定资产管理
import assetMgt from './modules/assetMgt'
// 项目管理
import itemMgt from './modules/itemMgt'
// 统报管理
import unifiedReportMgt from './modules/unifiedReportMgt'
//申报管理
import declarationMgt from './modules/declarationMgt'


Vue.use(Router)
//
let router = new Router({
    mode: 'hash',
    base: '/',
    routes: [
        {
            path: '/',
            name: 'home',
            component: require('../views/assetMgt/index').default,
            meta: {
                title: '资产管理'
            }
        },
        ...assetMgt,
        ...itemMgt,
        ...unifiedReportMgt,
        ...declarationMgt
    ]
})

router.beforeEach((to, from, next) => {
    let title = to.meta && to.meta.title
    if (title) {
        document.title = title // 设置页面 title
    }
    next() // 确保一定要调用 next()
})

const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
    return originalPush.call(this, location).catch(err => err)
}

export default router
